<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class PW_Profiler extends CI_Profiler
{
    protected $_print_data = array();
    
    public function __construct($config = array())
    {
        parent::__construct($config);
        $this->_available_sections [] = 'print_data';
    }
    
    protected function _compile_print_data()
    {
        if (empty($this->_print_data)) {
            return;
        }
        
        $output  = "\n\n";
        $output .= '<fieldset id="ci_profiler_pdata" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
        $output .= '<legend style="color:#995300;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_print_data').'&nbsp;&nbsp;</legend>';
        $output .= "<table style='width:100%' id='ci_profiler_print_data'>";
        
        foreach ($this->_print_data as $key => $val) {
            if (is_array($val) OR is_object($val)) {
                $val = print_r($val, TRUE);
            }
        
            $output .= "<tr><td style='padding:5px; vertical-align: top;color:#900;background-color:#ddd;'>".$key."&nbsp;&nbsp;</td><td style='padding:5px; color:#000;background-color:#ddd;'><pre>".htmlspecialchars($val)."</pre></td></tr>\n";
        }
        
        $output .= '</table>';
        $output .= "</fieldset>";
        return $output;
    }
    
    protected function format_array($input)
    {
        $str = '';
        if (is_array($input)) {
            foreach ($input as $key => $val) {
                $str .= $key . ' => ' . $this->format_array($val) . "\n";
            }
        } else {
            $str .= $input;
        }
        
        return $str;
    }
    
    public function print_data($name, $data)
    {
        $this->_print_data[$name] = $data;
    }
    
    /**
     * Show the controller and function that were called
     *
     * @return	string
     */
    protected function _compile_controller_info()
    {
        $output  = "\n\n";
        $output .= '<fieldset id="ci_profiler_controller_info" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
        $output .= "\n";
        $output .= '<legend style="color:#995300;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_controller_info').'&nbsp;&nbsp;</legend>';
        $output .= "\n";
    
        $output .= "<div style='color:#995300;font-weight:normal;padding:4px 0 4px 0'>"
                  ."<span style='display:inline-block;width:65px;'>Module:</span>".$this->CI->router->fetch_module()."<br />"
                  ."<span style='display:inline-block;width:65px;'>Controller:</span>".$this->CI->router->fetch_class()."<br />"
                  ."<span style='display:inline-block;width:65px;'>Function:</span>".$this->CI->router->fetch_method()."</div>";
    
        $output .= "</fieldset>";
    
        return $output;
    }
}

?>